package com.example.bookstore.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bookstore.common.PageResult;
import com.example.bookstore.common.Result;
import com.example.bookstore.dto.QueryBookParamsDto;
import com.example.bookstore.entity.Book;
import com.example.bookstore.mapper.BookMapper;
import com.example.bookstore.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;

    @PostMapping("/page")
    public PageResult<Book> selectByPageAndCondition(int currentPage, int pageSize, @RequestBody(required = false) QueryBookParamsDto params){
        PageResult<Book> bookPageResult = bookService.selectByPageAndCondition(currentPage, pageSize, params);
        return bookPageResult;
    }
    @GetMapping("/no/{bookId}")
    public Book selectByBookId(@PathVariable String bookId){
        return bookService.selectByBookId(bookId);
    }
    @GetMapping("/{id}")
    public Book selectById(@PathVariable int id){
        Book book = bookService.getById(id);
        return book;
    }
    @PutMapping
    public Result<String> addBook(@RequestBody Book book){
        Result<String> stringResult = bookService.addBook(book);
        return stringResult;
    }
    @PostMapping
    public Result<String> updateBook(@RequestBody Book book){
        Result<String> stringResult = bookService.updateBook(book);
        return stringResult;
    }
    @PostMapping("/image")
    public Result<String> updateBookImg(@RequestBody Book book){
        Result<String> stringResult = bookService.updateBookImg(book);
        return stringResult;
    }
    @DeleteMapping
    public Result<String> deleteBook(@RequestBody List<Long> ids){
        Result<String> stringResult = bookService.deleteBook(ids);
        return stringResult;
    }
    @PostMapping("/up")
    public Result<String> up(@RequestBody List<Long> ids){
        Result<String> stringResult = bookService.up(ids);
        return stringResult;
    }
    @PostMapping("/down")
    public Result<String> down(@RequestBody List<Long> ids){
        Result<String> stringResult = bookService.down(ids);
        return stringResult;
    }
}
